#ifndef __tenacitas_distributed__echo_call_handler__h__
#define __tenacitas_distributed__echo_call_handler__h__


// =============================================================================
/**
   @file 
   File description
*/


// =============================================================================
//                                 C++ Headers

#include<string>

// =============================================================================
//                                 3rds Headers


// =============================================================================
//                                 Our Headers


// =============================================================================
//                                 Namespaces
using namespace std;


// =============================================================================
//                                 Macro Contants

/**
 */


// =============================================================================
//                                 Macro Commands

/**
 */


/**
   namespace of the organization
*/
namespace tenacitas {
    /**
       namespace for the project
    */
    namespace distributed {

        // =====================================================================
        //                             Typedefs

        /**
         */


        // =====================================================================
        //                             Pre-Declarations


        // =====================================================================
        //                             Attributes

        /**
         */


        // =====================================================================
        //                             Functions

        /**
         */


        // =====================================================================
        //                             Classes

        /** 
            A call handler that just echoes every message that the client sends,
            until the client sends a message with "-1"
            @nosubgrouping 
        */
        template <typename t_call,
                  typename t_network,
                  typedef t_logger>
        class echo_call_handler {

            // -----------------------------------------------------------------
            //    echo_call_handler - Friends

        public:

            // -----------------------------------------------------------------
            //    echo_call_handler - Public Internal Types

            typedef echo_call_handler * ptr_type;
            
            typedef t_network network_type;

            /** Type of pointer for the @p network_type */
            typedef typename network_type::ptr_type network_ptr_type;

            typedef t_logger logger_type;

            /** Type of pointer for the @p logger_type */
            typedef typename logger_type::ptr_type logger_ptr_type;
            
            // -----------------------------------------------------------------
            //    echo_call_handler - Public Constructors

            /** Constructor */
            echo_call_handler( network_ptr_type & p_network,
                               logger_ptr_type & p_logger )
                : m_network( p_network ),
                  m_logger( p_logger ) {}
            

            /**
               Destructor
            */
            ~echo_call_handler ( ) {}
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Public Accessors
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Public Helpers
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Public Processors

            /** Starts the @p echo_call_handler */
            void start( ) {}
            
               
            /** A method that will handle a call, echoing every message that the
                client sends, until the client sends a message with "-1"

                @param [in] p_call
                @param [in] p_network
                @param [in] p_logger
             */
            void handle(const call_type & p_call,
                        network_ptr_type & p_network,
                        logger_ptr_type & p_logger ) {

                while ( true ) {
                    string l_msg = m_network->get( );
                    if ( l_msg == "-1" ) {
                        break;
                    }
                    else {
                        m_network->send( l_msg );
                    }
                }
            }
            
                           
            
            /** A method that makes the call handler ignore calls */
            void stop( ) {}

            // -----------------------------------------------------------------
            //    echo_call_handler - Public Operators
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Public Attributes
            

        private:

            // -----------------------------------------------------------------
            //    echo_call_handler - Private Internal Types
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Private Constructors
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Private Accessors
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Private Helpers
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Private Processors
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Private Operators
            

            // -----------------------------------------------------------------
            //    echo_call_handler - Private Attributes
            
            network_ptr_type m_network;
            
            logger_ptr_type m_logger;
            
        };

    }
}



#endif
